import intance from '@/utils'

export const loginApi = (data) => {
  return intance({
    method: 'post',
    url: 'login',
    data
  })
}
export const navMenuApi = () => {
  return intance({
    url: 'menus'
  })
}
export const usersApi = (params) => {
  return intance({
    url: 'users',
    params
  })
}
export const addUsersApi = (data) => {
  return intance({
    method: 'post',
    url: 'users',
    data
  })
}
// 修改用户状态
export const usersTypeApi = (id, type) => {
  return intance({
    method: 'put',
    url: 'users/' + id + '/state/' + type
  })
}
// 删除用户
export const removeUserApi = (id) => {
  return intance({
    method: 'delete',
    url: `users/${id}`
  })
}
// 编辑用户
export const alterUserApi = (data) => {
  return intance({
    method: 'put',
    url: `users/${data.id}`,
    data: {
      email: data.email,
      mobile: data.mobile
    }
  })
}
// 获取商品分类
export const categoriesApi = (params) => {
  return intance({
    url: 'categories',
    params
  })
}
// 分类参数管理
export const addAttributesApi = (id, sel) => {
  return intance({
    url: 'categories/' + id + '/attributes',
    params: {
      sel
    }
  })
}
// 编辑提交参数
export const redactAttributesApi = (data) => {
  return intance({
    method: 'put',
    url: `categories/${data.id}/attributes/${data.attrId}`,
    data: {
      attr_name: data.attr_name,
      attr_sel: data.attr_sel,
      attr_vals: data.attr_vals
    }
  })
}
// 添加参数
export const addArgumentsApi = (data) => {
  return intance({
    method: 'post',
    url: `categories/${data.id}/attributes`,
    data: {
      attr_name: data.attr_name,
      attr_sel: data.attr_sel
    }
  })
}
// 商品分类
export const commodityApi = (params) => {
  return intance({
    method: 'get',
    url: 'goods',
    params
  })
}
// 添加商品分类
export const addGoodsApi = (data) => {
  return intance({
    method: 'post',
    url: 'goods',
    data
  })
}
